
 *******Table 4*************************************************
 use "$data\analysisdata.dta", clear

* generate globals for sets of controls
global controlkid childageyears female genderage birthorder
global controlwoman mbase_ageyears  fdstotal rantime ranerror numberkids
global controlhh land members adults mbase_electrified  mbase_OB mbase_scheduled

* generate global for sets of dependent variables
global depkid education admission_school absentschool dropoffatschool askingforhomework timespenthomework womanhelphomework anyhelp days_sick medicalhelp placeofmedicalhelp presence_woman_treatment educationyears Mathtot totletterspm totsylpm totwordpm totnonwordpm totgrade1wpm totgrade2wpm
global depwoman cover treatwater washhands kidchat contraception timecooking earn dohome remind talkteach consultnurse
global depwomanmech ideal_Children- Pmela3
global games table2-perception_hus


 *Sequence and strata
 encode string_strata, generate(stratalottery)
 sort learnerid childwithinHHID
 bysort learnerid round: gen sequence=_n

 *sample
 keep if round=="endline" & ITTanalysis~=.
 
 
 replace anyhelp=0 if pid_helpedinhome=="T"
 gen tutor=0 if anyhelp!=.
 replace tutor=1 if pid_helpedinhome=="T"
 
 ****Table 4 Panel A
 estimates clear
 ivregress 2sls admission_school (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if childageyears>=6 & childageyears<=16, cluster(learnerid)
 est store admission_school
 su admission_school if ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 
 foreach i in Dabsentschool dropoffatschool askingforhomework Dtimespenthomework womanhelphomework tutor{
 ivregress 2sls `i'  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if childageyears>=6 & childageyears<=16 & admission_school==1, cluster(learnerid)
 est store `i'
 su `i' if ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 }
 
 ****Table 4 Panel B
 ivregress 2sls Ddays_sick  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if  childageyears<=16, cluster(learnerid) first
 est store Ddays_sick
 su Ddays_sick if ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 
 
 ivregress 2sls medicalhelp  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if Ddays_sick==0 & childageyears<=16, cluster(learnerid)
 est store medicalhelp
 su medicalhelp if ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 
 foreach i in placeofmedicalhelp presence_woman_treatment{
 ivregress 2sls `i'  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if medicalhelp==1 & childageyears<=16, cluster(learnerid)
 est store `i'
 su `i' if ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 }
 
 esttab * using "$results\Table4.xls", stat(controlmean N r2) keep (participatedTA_IV) b(3) se(3) replace
 
 ***FDR q-values
 *The FDR Q-values are computed following  Benjamini and Hochberg (1995) within each category.
 exit
 
 
